The present invention, in some embodiments thereof, relates to a computer implemented method of improving JavaScript code by adding local variables in place of global variables and, more specifically, but not exclusively, using a combination of multiple static inter procedural analysis methods to identify global variables. JavaScript™ is trademarked by ORACLE AMERICA, INC.
As technology advances and software intensive application become more abundant, software development is being done by a rapidly growing number of programmers who may have limited experience and may not be fully familiar with proper software development practices. Moreover, a lot of software practices used in certain environments, for example, Object Oriented Programming (OOP), web and/or server, may not fit platforms and applications of other nature, for example mobile platforms and/or Internet of Things (IoT). However software development practices may often be migrated from one software development environment to another. This migration may not be optimal at best and ineffective and/or harmful at worst.
In the case of JavaScript, which is a is a high-level, dynamic, untyped, and interpreted programming language, maintaining correct software engineering practices related to global variables can have a major positive impact on the JavaScript code life cycle, including development, debugging, integration, verification, deployment, upgrade and maintenance. Identifying poor programming at an early stage of the development process presents multiple benefits, for example, improving software code with respect to functionality and/or robustness, reduce implementation resources and/or reduce costs during one or more of the software product life cycle.
A common JavaScript software practice that negatively affects performance and maintainability is use of global variables in nested functions. Global variables can be accessed from anywhere in the code, allowing unintended changes to data. The referencing of a global variable takes more computing resources and time than referencing a local variable, since when executed JavaScript will first search for a variable in the local environment, and if not found continue to search elsewhere.
An important tool in ensuring good software engineering in JavaScript code is static analysis. The term static analysis as it relates to computer code typically refers to analysis of the instructions of a computer program that does not rely on the run-time execution of the application. One type of static analysis, known as inter procedural control flow graph, is a useful starting point in maintaining good JavaScript software engineering practices.